/* $RCSFile: ADNDynAccount.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynAccount.cs $
 * $log$
 * Revision 19 2010/10/02 14:01:48  christian.surieux
 *   Corrected a bug in allmost everyADNDyn file for PrimaryFieldVualue
 * Revision 6 2010/08/06 19:56:32  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using CrmSdk;
using AddonNice.CRMWrapper;

namespace AddonNice.CRMWrapper
{
	public class ADNDynAccount : ADNDynCustomer
	{
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.account)
            {}

            public override Type DynType
            { get { return typeof(ADNDynAccount); } }

            public override string DynTypename
            {   get{ return CrmStr.account;}}

            public override DynEntity Build()
            {
                return new ADNDynAccount();
            }
            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynAccount(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynAccount(w, PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynAccount(w,PrimaryKeyValue);}
        }

        static ADNDynAccount(){new Ftor();} 

        public override string SchemaName
        {
           get
           {
               if ( string.IsNullOrEmpty(_SchemaName) )
                    _SchemaName =   CrmStr.account;
               return _SchemaName;
           }
           set{}
        }

        public override ADNTypeCodes ADNTypeCode
        {   get{ return ADNTypeCodes.Account; }}


        public override int ObjectTypeCode
        {
           get
           {
               if ( _ObjectTypeCode == 0 )
                    _ObjectTypeCode    =   1;
               return _ObjectTypeCode;
           }
           set{}
        }

        /// <summary>
		/// Reserved for template methods: do not use directly
		/// </summary>
        public ADNDynAccount(): base()
		{}

		public ADNDynAccount(CRMWrapperBase w, string wname)
			: base(w,CrmStr.account)
		{
			name =  wname;
		}

		public ADNDynAccount(CRMWrapperBase w, Guid CrmId)
			: base(w,CrmStr.account, CrmId)
		{}

		public ADNDynAccount(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w,CrmStr.account,e,null,null)
		{}

		public ADNDynAccount(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
           : base(w,CrmStr.account,e,prop,s)
		{}

		public ADNDynAccount(ResetWrapperHandler fn, Guid CrmId)
			: base(fn,CrmStr.account, CrmId)
		{}

		public ADNDynAccount(ResetWrapperHandler fn, InternalDynamicEntity e)
			: base(fn,CrmStr.account,e,null,null)
		{}

		public ADNDynAccount(ResetWrapperHandler fn, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
           : base(fn,CrmStr.account,e,prop,s)
		{}

        [CrmDynAttribute(CrmStr.account)]
        public Guid accountid
		{
			get
			{
				return KeyPropertyValue(CrmStr.accountid);
			}
			set
			{
				AddKeyProperty(CrmStr.accountid, value);
			}
		}
        
        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.accountid) || KeyPropertyValue(CrmStr.accountid) != crmId )
                accountid   =   crmId;
        }
        
        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return accountid;
           }
           set
           {
               accountid    =   value;
           }
        }

        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.name;
            }
           set
           {}
       }

        public override string PrimaryFieldStringValue
        {
            get
            {
                return name;
            }
            set
            {
                name =   value;
            }
        }

        /// <summary>
        /// Here just for CrmDynAttribute
        /// </summary>
        [CrmDynAttribute(CrmStr.account)]
        public Guid owningbusinessunit
        {
            get
            {
                return LookupPropertyValue(CrmStr.owningbusinessunit);
            }
            set
            {
                AddLookupProperty(CrmStr.owningbusinessunit,CrmStr.businessunit,value);
            }
        }

        /// <summary>
        /// Owner for this object
        /// </summary>
        [CrmDynAttribute(CrmStr.account)]
        public override Guid ownerid
        {
            get
            {
                if ( ContainsKey(CrmStr.ownerid) )
                    return OwnerPropertyValue(CrmStr.ownerid);
                return Guid.Empty;
            }
            set
            {
                AddOwnerProperty(CrmStr.ownerid,CrmStr.systemuser,value);
            }
        }

        [CrmDynAttribute(CrmStr.account)]
        public Guid parentaccountid
		{
			get
			{
                if ( dicProperty.ContainsKey(CrmStr.parentaccountid) )
				    return LookupPropertyValue(CrmStr.parentaccountid);
                return Guid.Empty;
			}
			set
			{
				AddLookupProperty(CrmStr.parentaccountid,CrmStr.account,value);
			}
		}

        [CrmDynAttribute(CrmStr.account)]
        public Guid preferredequipmentid
		{
			get
			{
				return LookupPropertyValue(CrmStr.preferredequipmentid );
			}
			set
			{
				AddLookupProperty(CrmStr.preferredequipmentid,CrmStr.equipment,value);
			}
		}

        public string preferredequipmentidName
		{
			get
			{
                if ( dicProperty.ContainsKey(CrmStr.preferredequipmentid) )
    				return LookupPropertyName(CrmStr.preferredequipmentid );
                return string.Empty;
			}
		}

        [CrmDynAttribute(CrmStr.account)]
        public Guid preferredserviceid 
		{
			get
			{
				return LookupPropertyValue(CrmStr.preferredserviceid );
			}
			set
			{
				AddLookupProperty(CrmStr.preferredserviceid,CrmStr.service,value);
			}
		}

        public string preferredserviceidName
		{
			get
			{
                if ( dicProperty.ContainsKey(CrmStr.preferredserviceid) )
    				return LookupPropertyName(CrmStr.preferredserviceid );
                return string.Empty;
			}
		}

        [CrmDynAttribute(CrmStr.account)]
        public Guid preferredsystemuserid 
		{
			get
			{
				return LookupPropertyValue(CrmStr.preferredsystemuserid );
			}
			set
			{
				AddLookupProperty(CrmStr.preferredsystemuserid,CrmStr.systemuser,value);
			}
		}

        public string preferredsystemuseridName
		{
			get
			{
                if ( dicProperty.ContainsKey(CrmStr.preferredsystemuserid) )
    				return LookupPropertyName(CrmStr.preferredsystemuserid );
                return string.Empty;
			}
		}

        [CrmDynAttribute(CrmStr.account)]
        public Guid defaultpricelevelid
		{
			get
			{
                if ( ContainsKey(CrmStr.defaultpricelevelid) )
				    return LookupPropertyValue(CrmStr.defaultpricelevelid );
                return Guid.Empty;
			}
			set
			{
				AddLookupProperty(CrmStr.defaultpricelevelid,CrmStr.pricelevel,value);
			}
		}

        public string defaultpricelevelName
		{
			get
			{
                if ( dicProperty.ContainsKey(CrmStr.defaultpricelevelid) )
    				return LookupPropertyName(CrmStr.defaultpricelevelid );
                return string.Empty;
			}
		}

        /// <summary>
        /// Net 30
        /// 2% 10, Net 30
        /// Net 45
        /// Net 60
        /// </summary>
        [CrmDynAttribute(CrmStr.account)]
        public int paymenttermscode  
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.paymenttermscode);
            }
            set
            {
                AddPicklistProperty(CrmStr.paymenttermscode,value);
            }
        }
         
        public string paymenttermscodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.paymenttermscode);
            }
        }

        /// <summary>
        /// No values on install
        /// </summary>
        [CrmDynAttribute(CrmStr.account)]
        public int shippingmethodcode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.shippingmethodcode);
			}
			set
			{
				AddPicklistProperty(CrmStr.shippingmethodcode,value);
			}
		}

        public string shippingmethodcodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.shippingmethodcode) )
                    return PicklistPropertyLabelValue(CrmStr.shippingmethodcode);
                return string.Empty;
            }
        }

        /// <summary>
        /// Sunday
        /// Monday
        /// Tuesday
        /// Wednesday
        /// Thursday
        /// Friday
        /// Saturday
        /// </summary>
        [CrmDynAttribute(CrmStr.account)]
        public int preferredappointmentdaycode  
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.preferredappointmentdaycode);
            }
            set
            {
                AddPicklistProperty(CrmStr.preferredappointmentdaycode,value);
            }
        }
         
        public string preferredappointmentdaycodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.preferredappointmentdaycode);
            }
        }

        /// <summary>
        /// Any ->default
        /// E-mail
        /// Phone
        /// Fax
        /// Mail
        /// </summary>
        [CrmDynAttribute(CrmStr.account)]
        public int preferredcontactmethodcode  
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.preferredcontactmethodcode);
            }
            set
            {
                AddPicklistProperty(CrmStr.preferredcontactmethodcode,value);
            }
        }
         
        public string preferredcontactmethodcodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.preferredcontactmethodcode);
            }
        }

        [CrmDynAttribute(CrmStr.account)]
        public int industrycode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.industrycode);
			}
			set
			{
				AddPicklistProperty(CrmStr.industrycode,value);
			}
		}
        
        public string industrycodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.industrycode) )
                    return PicklistPropertyLabelValue(CrmStr.industrycode);
                return string.Empty;
            }
        }
        
        /// <summary>
        /// Public
        /// Private
        /// Subsidiary
        /// Other
        /// </summary>
        [CrmDynAttribute(CrmStr.account)]
        public int ownershipcode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.ownershipcode);
			}
			set
			{
				AddPicklistProperty(CrmStr.ownershipcode,value);
			}
		}

        public string ownershipLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.ownershipcode) )
                    return PicklistPropertyLabelValue(CrmStr.ownershipcode);
                return string.Empty;
            }
        }
            
        string _DefaultPrimaryContact   =   CrmStr.contact;
        public string DefaultPrimaryContact
		{
			get
			{
				return _DefaultPrimaryContact;
			}
			set
			{
				_DefaultPrimaryContact  =   value;
			}
		}

        [CrmDynAttribute(CrmStr.account)]
        public Guid primarycontactid
		{
			get
			{
                if ( dicProperty.ContainsKey(CrmStr.primarycontactid) )
				    return LookupPropertyValue(CrmStr.primarycontactid);
                return Guid.Empty;
			}
			set
			{
				AddLookupProperty(CrmStr.primarycontactid,DefaultPrimaryContact ,value);
			}
		}

        public string primarycontactName
		{
			get
			{
                if ( dicProperty.ContainsKey(CrmStr.primarycontactid) )
				    return LookupPropertyName(CrmStr.primarycontactid);
                return string.Empty;
			}
		}

        [CrmDynAttribute(CrmStr.account)]
        public string primarycontacttype
		{
			get
			{
                if ( dicProperty.ContainsKey(CrmStr.primarycontactid) )
				    return LookupPropertyType(CrmStr.primarycontactid);
                return string.Empty;
			}
		}

        [CrmDynAttribute(CrmStr.account)]
        public string accountnumber 
		{
			get
			{
				return StringPropertyValue(CrmStr.accountnumber);
			}
			set
			{
				AddStringProperty(CrmStr.accountnumber, value);
			}
		}
    
        [CrmDynAttribute(CrmStr.account)]
        public string sic
		{
			get
			{
				return StringPropertyValue(CrmStr.sic);
			}
			set
			{
				AddStringProperty(CrmStr.sic, value);
			}
		}

        [CrmDynAttribute(CrmStr.account)]
        public int numberofemployees
        {
            get
            {
                if ( ContainsKey(CrmStr.numberofemployees) )
                    return NumberPropertyValue(CrmStr.numberofemployees);
                return 0;
            }
            set
            {
                AddNumberProperty(CrmStr.numberofemployees,value);
            }
        }
        
        [CrmDynAttribute(CrmStr.account)]
        public decimal creditlimit
        {
            get
            {
                if ( ContainsKey(CrmStr.creditlimit) )
                    return MoneyPropertyValue(CrmStr.creditlimit);
                return 0m;
            }
            set
            {
                AddMoneyProperty(CrmStr.creditlimit,value);
            }
        }

        [CrmDynAttribute(CrmStr.account)]
        public decimal creditlimit_base
        {
            get
            {
                if ( ContainsKey(CrmStr.creditlimit_base) )
                    return MoneyPropertyValue(CrmStr.creditlimit_base);
                return 0m;
            }
        }
         
        [CrmDynAttribute(CrmStr.account)]
        public bool creditonhold
        {
            get 
            {
                return BooleanPropertyValue(CrmStr.creditonhold);
            }
            set
            {
                AddBooleanProperty(CrmStr.creditonhold,value);
            }
        }
         
        [CrmDynAttribute(CrmStr.account)]
        public decimal marketcap
        {
            get
            {
                if ( ContainsKey(CrmStr.marketcap) )
                    return MoneyPropertyValue(CrmStr.marketcap);
                return 0m;
            }
            set
            {
                AddMoneyProperty(CrmStr.marketcap,value);
            }
        }

        [CrmDynAttribute(CrmStr.account)]
        public decimal marketcap_base
        {
            get
            {
                if ( ContainsKey(CrmStr.marketcap_base) )
                    return MoneyPropertyValue(CrmStr.marketcap_base);
                return 0m;
            }
        }
         
        [CrmDynAttribute(CrmStr.account)]
        public decimal revenue
        {
            get
            {
                if ( ContainsKey(CrmStr.revenue) )
                    return MoneyPropertyValue(CrmStr.revenue);
                return 0m;
            }
            set
            {
                AddMoneyProperty(CrmStr.revenue,value);
            }
        }

        [CrmDynAttribute(CrmStr.account)]
        public decimal revenue_base
        {
            get
            {
                if ( ContainsKey(CrmStr.revenue_base) )
                    return MoneyPropertyValue(CrmStr.revenue_base);
                return 0m;
            }
        }

        [CrmDynAttribute(CrmStr.account)]
        public int customertypecode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.customertypecode);
			}
			set
			{
				AddPicklistProperty(CrmStr.customertypecode,value);
			}
		}

        public string customertypecodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.customertypecode) )
                    return PicklistPropertyLabelValue(CrmStr.customertypecode);
                return string.Empty;
            }
        }
        
        [CrmDynAttribute(CrmStr.account)]
        public int customersizecode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.customersizecode);
			}
			set
			{
				AddPicklistProperty(CrmStr.customersizecode,value);
			}
		}

        public string customersizecodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.customersizecode) )
                    return PicklistPropertyLabelValue(CrmStr.customersizecode);
                return string.Empty;
            }
        }
         
        /// <summary>
        /// Preferred Customer
        /// Standard
        /// </summary>
        [CrmDynAttribute(CrmStr.account)]
        public int accountcategorycode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.accountcategorycode);
			}
			set
			{
				AddPicklistProperty(CrmStr.accountcategorycode,value);
			}
		}

        public string accountcategorycodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.accountcategorycode) )
                    return PicklistPropertyLabelValue(CrmStr.accountcategorycode);
                return string.Empty;
            }
        }

        [CrmDynAttribute(CrmStr.account)]
        public int accountratingcode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.accountratingcode);
			}
			set
			{
				AddPicklistProperty(CrmStr.accountratingcode,value);
			}
		}

        public string accountratingcodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.accountratingcode) )
                    return PicklistPropertyLabelValue(CrmStr.accountratingcode);
                return string.Empty;
            }
        }
        
        [CrmDynAttribute(CrmStr.account)]
        public int accountclassificationcode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.accountclassificationcode);
			}
			set
			{
				AddPicklistProperty(CrmStr.accountclassificationcode,value);
			}
		}

        public string accountclassificationcodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.accountclassificationcode) )
                    return PicklistPropertyLabelValue(CrmStr.accountclassificationcode);
                return string.Empty;
            }
        }
        
        [CrmDynAttribute(CrmStr.account)]
        public int businesstypecode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.businesstypecode);
			}
			set
			{
				AddPicklistProperty(CrmStr.businesstypecode,value);
			}
		}

        public string businesstypecodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.businesstypecode) )
                    return PicklistPropertyLabelValue(CrmStr.businesstypecode);
                return string.Empty;
            }
        }
 
        /// <summary>
        /// Default value
        /// </summary>
        [CrmDynAttribute(CrmStr.account)]
        public int territorycode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.territorycode);
			}
			set
			{
				AddPicklistProperty(CrmStr.territorycode,value);
			}
		}

        public string territorycodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.territorycode) )
                    return PicklistPropertyLabelValue(CrmStr.territorycode);
                return string.Empty;
            }
        }
        
        [CrmDynAttribute(CrmStr.account)]
        public Guid territoryid
		{
			get
			{
				return LookupPropertyValue(CrmStr.territoryid );
			}
			set
			{
				AddLookupProperty(CrmStr.territoryid,CrmStr.territory,value);
			}
		}

        public string territoryidName
		{
			get
			{
                if ( dicProperty.ContainsKey(CrmStr.territoryid) )
    				return LookupPropertyName(CrmStr.territoryid );
                return string.Empty;
			}
		}
        
        [CrmDynAttribute(CrmStr.account)]
        public string tickersymbol 
		{
			get
			{
				return StringPropertyValue(CrmStr.tickersymbol);
			}
			set
			{
				AddStringProperty(CrmStr.tickersymbol, value);
			}
		}
    
        [CrmDynAttribute(CrmStr.account)]
        public string stockexchange 
		{
			get
			{
				return StringPropertyValue(CrmStr.stockexchange);
			}
			set
			{
				AddStringProperty(CrmStr.stockexchange, value);
			}
		}

        [CrmDynAttribute(CrmStr.account)]
        public string websiteurl 
		{
			get
			{
				return StringPropertyValue(CrmStr.websiteurl);
			}
			set
			{
				AddStringProperty(CrmStr.websiteurl, value);
			}
		}

        public enum AccountState : int
        {
            Active      =   0,// Specifies that the account is active. statuscode Active 1 
            Inactive    =   1 // Specifies that the account is inactive. statuscode Inactive 2 
        }

        public void SetState(AccountState st,int status,bool isAdmin)
        {
            wrapper.Util.SetAccountState(this,st,status,isAdmin);
        }

        #region Utilities

        public static ADNDynAccount FindAccountByName(CRMWrapperBase Wrapper,string searchedCompany,bool CreateIfNotFound,ref bool created)
        {
            bool created2       =   created;
            ADNDynAccount dynC     =   Wrapper.Util.FindAccountByName(searchedCompany, CreateIfNotFound,ref created2);
            created             =   created2;
            return dynC;
        }

        #endregion Utilities

    }
}
